package mortal.game.view.msgbroad
{
	import com.gengine.utils.*;
	import com.greensock.*;
	import flash.display.*;
	import flash.text.*;
	import flash.utils.*;
	import mortal.component.gconst.*;
	
	public class NoticeItem extends Sprite
	{
		private var _textField:TextField;
		private var _timerKey:int;
		private var _inTween:TweenMax;
		private var _upTween:TweenMax;
		private var _hideTween:TweenMax;
		private var _outTween:TweenMax;
		private var _endFun:Function;
		private var _hideCallBack:Function;
		private var _hideIng:Boolean;
		public var disposed:Boolean;
		
		public function NoticeItem()
		{
			mouseEnabled = false;
			mouseChildren = false;
			this._textField = new TextField();
			this._textField.selectable = false;
			this._textField.multiline = true;
			this._textField.wordWrap = true;
			this._textField.width = 800;
			this._textField.filters = [FilterConst.noticeItemFilter];
			var textFormat:TextFormat = new TextFormat("宋体", 16, 16776960, false, null, null, null, null, TextFormatAlign.CENTER, null, null, null, 4);
			textFormat.letterSpacing = 2;
			this._textField.defaultTextFormat = textFormat;
			this._textField.autoSize = TextFieldAutoSize.CENTER;
			addChild(this._textField);
		}
		
		private function onInEnd() : void
		{
			this._timerKey = setTimeout(this.timerOutHandler, 3000);
		}
		
		private function onOutEnd() : void
		{
			if (this._endFun != null)
			{
				this._endFun.call(this, this);
			}
		}
		
		private function onHideEnd() : void
		{
			this._hideIng = false;
			if (this._hideCallBack != null)
			{
				this._hideCallBack.call(this, this);
			}
		}
		
		private function timerOutHandler() : void
		{
			this._outTween = TweenMax.to(this._textField, 0.5, {alpha:0.2, onComplete:this.onOutEnd});
		}
		
		public function updateData(param1:String, param2:Function, param3:int = 70, param4:Boolean = true) : void
		{
			this.disposed = false;
			this._textField.htmlText = HTMLUtil.addColor(param1, "#ffff00");
			this._textField.height = this._textField.textHeight;
			this._endFun = param2;
			if (param4)
			{
				this._textField.alpha = 0.5;
				this._textField.y = param3;
				this._inTween = TweenMax.to(this._textField, 0.3, {alpha:1, y:0, onComplete:this.onInEnd});
			}
			else
			{
				this._textField.alpha = 1;
				this._textField.y = 0;
				this.onInEnd();
			}
		}
		
		public function easeUp(Y:int) : void
		{
			this._upTween = TweenMax.to(this, 0.3, {y:Y});
		}
		
		public function easeHide(hideCallBack:Function) : void
		{
			this._hideIng = true;
			this._hideCallBack = hideCallBack;
			this._hideTween = TweenMax.to(this._textField, 0.3, {y:-20, alpha:0.5, onComplete:this.onHideEnd});
		}
		
		public function killInEase() : void
		{
			if (this._inTween && this._inTween.active)
			{
				this._textField.y = 0;
				this._textField.alpha = 1;
				this._inTween.kill();
				this.onInEnd();
			}
		}
		
		public function dispose() : void
		{
			this._hideCallBack = null;
			this._hideIng = false;
			this._endFun = null;
			clearTimeout(this._timerKey);
			if (this._inTween && this._inTween.active)
			{
				this._inTween.kill();
			}
			if (this._outTween && this._outTween.active)
			{
				this._outTween.kill();
			}
			if (this._upTween && this._upTween.active)
			{
				this._upTween.kill();
			}
			if (this._hideTween && this._hideTween.active)
			{
				this._hideTween.kill();
			}
			this._textField.alpha = 1;
			this._textField.y = 0;
			this.disposed = true;
		}
		
		public function get hideIng() : Boolean
		{
			return this._hideIng;
		}
		
		override public function get height() : Number
		{
			return this._textField.textHeight;
		}
		
		override public function get width() : Number
		{
			return this._textField.width;
		}
	}
}
